<%-- 
    Document   : UserSearch
    Created on : Nov 25, 2011, 3:50:15 PM
    Author     : ferru001
--%>

<%@ include file="/WEB-INF/views/includes.jsp" %>
<%@ page import="com.cheapflix.beans.User" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link rel="stylesheet" type="text/css" href="/cheapflix/css/style.css" />
        <script type="text/javascript" src="<%=request.getContextPath()%>/js/login.js"/>
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
    </head>
    <body>
        <div class="outer">
            <%@ include file="/WEB-INF/views/header.jsp" %>
            <div class="row rowstyle">
                <h1>Search For Users</h1>
                <form action="/cheapflix/usersearch" method="GET" style="margin-bottom:20px;">
                    <input type="text" name="q" value='<c:out value="${param.q}"/>'/>
                    <input type="submit" value="Search"/>
                </form>
                <c:if test="${result != null && fn:length(result) > 0}">
                    <table border="1" class="stdTable">
                        <tr><th>Add as friend</th><th>username</th><th>name</th></tr>
                        <c:forEach var="founduser" items="${result}">
                            <%
                                User founduser = (User) pageContext.getAttribute("founduser");
                                User me = (User) session.getAttribute("me");
                                System.out.println("me: " + me);
                                System.out.println("foundUser: " + founduser);
                                if( me.getFriend(founduser.getId()+"") != null ){
                                    %>
                                    <tr><td>My FlixFriend!</td><td><c:out value="${founduser.username}"/></td><td><c:out value="${founduser.nameFirst}"/> <c:out value="${founduser.nameLast}"/></td></tr>
                                    <%
                                }else{%>
                                    <tr><td><a href='/cheapflix/frienduser/<c:out value="${founduser.id}"/>'>Friend user</a></td><td><c:out value="${founduser.username}"/></td><td><c:out value="${founduser.nameFirst}"/> <c:out value="${founduser.nameLast}"/></td></tr>
                                <%}
                            %>
                        </c:forEach>
                    </table>
                </c:if>
            </div>
                     <%@ include file="/WEB-INF/views/footer.jsp" %>
        </div>
    </body>
</html>
